#!/usr/bin/perl
# Version 0.2.1

$testcase = "lsa_multicast";

# 1 = PASS
# 2 = FAIL
# 3 = INCONCLUSIVE
$verdict = 3;

$dumpfile = "$testcase.dump";
$logfile = "$testcase.log";

if ($#ARGV ne 1) {
        print("Usage: $testcase.pl dump_file log_file");
        exit 1;
}

$dumpfile = $ARGV[0];
$logfile = $ARGV[1];

#------------------------------------------------------------------------------

$success = 1;
$state = 0;
$found = 0;
open(DUMPFILE, $dumpfile) or $success = 0;

if($success) {
	while(<DUMPFILE>) {
		@l = split(/ /, $_);
		
		# now look at the time
		@ti = split(/\./, $l[0]);
		@ts = split(/:/, $ti[0]);
			
		$secs = $ts[2] + ($ts[1] + $ts[0] * 60) * 60; # secs contains the sim time in seconds

		# look only at LS-updates from 0.0.0.1
		if($_ =~ /0\.0\.0\.1 > (.*): OSPFv2-ls_upd (.*) rtr 0\.0\.0\.1/) {
			if(($secs > 50) && ($secs < 100)) {
				$found = $found | 1;
				
				if( $1 ne "224.0.0.5" ) {
					$state = $state | 1;
				}
			}
			if(($secs > 125) && ($secs < 175)) {
				$found = $found | 2;
				
				if( $1 ne "224.0.0.5" ) {
					$state = $state | 2;
				}
			}
			if($secs > 200) {
				$found = $found | 4;
				
				if( $1 ne "224.0.0.6" ) {
					$state = $state | 4;
				}
			}
		}
	}
	
	if(($found eq 7) && ($state eq 0)) {
		$verdict = 1;
		print("All updates are sent to te correct multicast addresses. Test PASSED.\n");
	} else {
		$verdict = 2;
		
		if($found ne 7) {
			print("Some updates could not be found. ");
		}
		if($state ne 0) {
			print("Some packets were not sent to the correct address. ");
		}
		print(" Test FAILED.\n");
	}
}

if($verdict eq 3 ) {
	print("Cannot evaluate test results. Test INCONLUSIVE.\n");
}

#------------------------------------------------------------------------------
print("### VERDICT for $testcase: ");

if ($verdict eq 1) { 
        print("PASS"); 
} elsif ($verdict eq 2) {
        print("FAIL");
} else {
        print("INCONCLUSIVE");
}

print(" ###\n");